import wx

import sys

sys.path.append('..')

import config.config as config

def color_converter(color_list, multiplier = None):
	colors = [ c * 2.55 for c in color_list[:-1] ]
	alpha = (100 - color_list[3]) * 2.55 * (100 - float(config.transparency)) / 100
	colors.append( alpha )
	if multiplier:
		colors[3] = ( 1- (1 - colors[3]/255.0) ** multiplier )* 255
		
	colors = [int(color) for color in colors]
	return wx.Colour( colors[0], colors[1], colors[2], colors[3] )
		
def get_color(color, index = None):
	schema = config.color_current
	color_dict = config.colors[schema]
	if index != None:
		return color_converter(color_dict[color][index])
	else:
		return color_converter(color_dict[color])

	
def get_html_color(color, index = None):
	colors = get_fake_color(color, index)
	colors = [hex(int(color))[2:] for color in colors]
	colors = [color.rjust(2, '0') for color in colors]
	return ''.join(colors)
	
def get_fake_color(color, index=None):
	wx_color = get_color(color, index)
	colors = [wx_color.Red(), wx_color.Green(), wx_color.Blue()]
	alpha = wx_color.Alpha()
	alpha = float(alpha)
	
	# hack for double alpha
	alpha = ( 1- (1 - alpha/255.0) ** 2 )* 255
	
	# hack for mac
	bg_theme_color = 0.931
	return [color * alpha / 255 + bg_theme_color * (255 - alpha) for color in colors]

